public class Ball {
  float ballRadius;
  color ballColor;

  PVector ballPosition;
  PVector ballGoal; // Meta a la cual llegar

  public Ball(float newRadius, color newColor, PVector newPosition) {
    ballRadius = newRadius;
    ballColor = newColor;

    ballPosition = newPosition;

    initGoal();
  }

  public void initGoal() {
    float goalX = random ( width * 0.1 , width * 0.9 );
    float goalY = random ( height * 0.1 , height * 0.9 );

    ballGoal = new PVector ( goalX, goalY );
    
    gNotificationManager.notify(1, gNotification);
  }

  public void draw() {    
    if ( hasReachedGoal() ) {
      initGoal();
    }
      
    stroke( 0 );
    fill (255,0,0);
    ellipse ( ballGoal.x, ballGoal.y , 10 , 10);
    
    stroke( 0 );
    fill( ballColor );
    ellipse( ballPosition.x, ballPosition.y, ballRadius*2, ballRadius*2 );
  }
  
  private boolean hasReachedGoal(){
    boolean reachedGoal = false;
    float distance = ballGoal.dist( ballPosition );
    
    if ( distance <= ballRadius ){
      reachedGoal = true;
    }
    
    return reachedGoal;
  }

  public void moveBall( PVector ballVelocity ) {
    if ( !(((ballPosition.x + ballVelocity.x) >= ballRadius) && ((ballPosition.x + ballVelocity.x) <= (width - ballRadius))) ) {
      ballVelocity.x = 0;
    }

    if (!( ((ballPosition.y + ballVelocity.y) >= ballRadius) && ((ballPosition.y + ballVelocity.y) <= (height - ballRadius)) ) ) {
      ballVelocity.y = 0;
    }

    ballPosition.add(ballVelocity);
  }
}

